

import { createSlice } from "@reduxjs/toolkit";

import { addaccountApi } from '../../apis/userApi';

const addCountSlice= createSlice({

    name:"addCount",

    initialState:{
        loading:false
    },

    reducers:{
        setLoading(state, action) {
            state.loading = action.payload;
        },

    }

})

export const {setLoading} =addCountSlice.actions
export default addCountSlice.reducer;


//异步请求

export const addcount=(values)=>(dispatch)=>{

    addaccountApi(values)
    .then(res=>{
      // setLoading(false)
      dispatch(setLoading(false))
      message.success('添加成功')
      //清除表单上的数据
      console.log('refData.current',refData.current)
      refData.current.resetFields()
    })
    .catch(res=>{
      // setLoading(false)
      dispatch(setLoading(false))
    })


}

